export const SubmitWebSocket = class {

    constructor(submitId, messageFunc) {
        this.ws = new WebSocket(`ws://localhost:8400/ws/submit/${submitId}`);

        this.ws.onopen = (evt) => {
            console.log("连接已建立...");
            this.ws.send("--websocket 连接测试数据--")
        };

        this.ws.onmessage = (evt) => {
            const rs = JSON.parse(evt.data);
            messageFunc(rs);
        };

        this.ws.onclose = (evt) => {
            console.log("连接已关闭...");
        };
    }

    send = (data) => {
        this.ws.send(data);
    }

    close = () => {
        this.ws.close();
    }
}

